package cn.itcast.listener;

import cn.itcast.utils.MailUtils;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.listener.api.ChannelAwareMessageListener;

import java.util.Map;

public class MyListener implements ChannelAwareMessageListener {
    @Override
    public void onMessage(Message message, Channel channel) throws Exception {
        //获取数据,转换成map集合
        Map<String,String> map = new ObjectMapper().readValue(message.getBody(), Map.class);

        //获取map中所有key
        String emailTo = map.get("emailTo");
        String emailSubject = map.get("emailSubject");
        String emailContent = map.get("emailContent");

        //调用工具类发送邮件'
        MailUtils.sendMail(emailTo,emailSubject,emailContent);
    }
}
